package com.sky.controller.admin;

import com.sky.dto.EmployeeDTO;
import com.sky.dto.EmployeeLoginDTO;
import com.sky.dto.EmployeePageQueryDTO;
import com.sky.entity.Employee;
import com.sky.properties.JwtProperties;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.EmployeeService;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 员工管理
 */
@RestController
@RequestMapping("/admin/employee")
@Slf4j

public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;
    @Autowired
    private JwtProperties jwtProperties;

    /**
     * 登录
     *
     * @param employeeLoginDTO
     * @return
     */
    @PostMapping("/login")

    public Result<Employee> login(@RequestBody EmployeeLoginDTO employeeLoginDTO) {
        // 员工登录处理
        log.info("员工登录,{}",employeeLoginDTO);
        return Result.success(employeeService.login(employeeLoginDTO));
    }

    /**
     * 退出
     *
     * @return
     */

    @PostMapping("/logout")
    public Result<String> logout() {
        return Result.success();
    }

    @PostMapping

    public Result save(@RequestBody EmployeeDTO employeeDTO){
        log.info("新增员工:{}",employeeDTO);
        employeeService.save(employeeDTO);
        System.out.println(Thread.currentThread().getName());
        return Result.success();

    }
    @GetMapping("/page")

    public Result<PageResult> page(EmployeePageQueryDTO queryDTO){ //查询类使用泛型
        PageResult pageResult = employeeService.page(queryDTO);
        log.info("员工分页查询:{}",queryDTO);
        return Result.success(pageResult);
    }


    @PostMapping("/status/{status}")
    public Result SOS(@PathVariable Integer status,Long id){
        log.info("启用员工启用禁用:{},{}",id,status);
        employeeService.SOS(status,id);
        return Result.success();
    }


    @GetMapping("/{id}")
    public Result<Employee> getById(@PathVariable Long id){
        Employee employee = employeeService.getById(id);
        return Result.success(employee);
    }


    @PutMapping
    public Result update(@RequestBody EmployeeDTO employeeDTO){
        log.info("编辑员工信息:{}",employeeDTO);
        employeeService.update(employeeDTO);
        return Result.success();
    }






}
